//
//  SafeCenterViewController.m
//  PPDL
//
//  Created by 王洋 on 2019/7/24.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "PPSettingCell.h"
#import "SafeCenterViewController.h"
#import "ChangePhoneNumViewController.h"
#import "ChangeLoginPSWViewController.h"
#import "MyBankCardViewController.h"
#import "ChangeLoginPSWViewController.h"
#import "PayPSWSelectViewController.h"


@interface SafeCenterViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableview;

@property (nonatomic, strong) NSMutableArray <PP_jumpModel *>*listArray;

@property (nonatomic, strong) NSMutableArray *configArray;
@end

@implementation SafeCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self prepareData];
}

- (void)prepareData {
    
    self.listArray = @[].mutableCopy;
    
    for (int i = 0; i< self.configArray.count; i++) {
        
        NSDictionary *dic = self.configArray[i];
        PP_jumpModel *model = [PP_jumpModel new];
        model.title = [dic valueForKey:@"title"];
        model.className = [dic valueForKey:@"className"];
        model.type = (CommentClickType)[[dic valueForKey:@"type"] integerValue];
        model.ID = [dic valueForKey:@"ID"];;
        [self.listArray addObject:model];
    }
    
    [self.tableview reloadData];
    
}

- (void)initView {
    
    self.title = @"安全中心";
    
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.backgroundColor = PP_Default_Color_Gray_F1F1F1;
    [self.tableview registerNib:[UINib nibWithNibName:@"PPSettingCell" bundle:nil] forCellReuseIdentifier:@"PPSettingCellID"];
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableview reloadData];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PPSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"PPSettingCellID" forIndexPath:indexPath];
    cell.selectionStyle =UITableViewCellSelectionStyleNone;
    [cell fillCellWithModel:self.listArray[indexPath.row]];
    
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.listArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    PP_jumpModel *model = self.listArray[indexPath.row];
//    [[TTJumpManager share] pushViewControllerWithModel:model];
    
    [[TTJumpManager share] pushViewControllerWithClassName:model.className];
    
}


- (NSMutableArray *)configArray {
    
    //                 @{@"title":@"支付密码设置",@"className":@"PayPSWSelectViewController",@"ID":@""},

    
    if ([TTUserModel sharedObject].verifyType == Comment_Verify_Pass) {
        
        return @[
                 @{@"title":@"我的银行卡",@"className":@"MyBankCardViewController",@"ID":@""},
                 @{@"title":@"修改登录密码",@"className":@"ChangeLoginPSWViewController",@"ID":@""}
                 ].mutableCopy;
    } else {
        
        return @[
                 @{@"title":@"实名认证",@"className":@"RealNameAuthViewController",@"ID":@""},
                 @{@"title":@"我的银行卡",@"className":@"MyBankCardViewController",@"ID":@""},
                 @{@"title":@"修改登录密码",@"className":@"ChangeLoginPSWViewController",@"ID":@""}
                 ].mutableCopy;
    }
}

- (IBAction)logOut:(id)sender {
    
    [[TTUserModel sharedObject].userModelDefault setValue:@"unLoged" forKey:@"login_status"];
    [[TTUserModel sharedObject].userModelDefault synchronize];
    
    [[TTUserModel sharedObject] initialization];
    
    [self.navigationController popViewControllerAnimated:NO];
    [[PPTabBarController shareTabbar] setSelectedIndex:PPTabbarIndexTypeHome];
}

@end
